﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Vkontakte.Api.Operations
{
	[ApiMethod("messages.get")]
	public sealed class MessagesGet
		:Base30ApiOperation
	{
		private int _count;

		public MessagesGet()
		{
			PreviewLength = 90;
		}

		protected override void Compile()
		{
			AddParameter("method", "messages.get");
			if (Out)
			{
				AddParameter( "out","1" );
			}
			if (_count!=0)
			{
				AddParameter( "count",_count.ToString() );
			}
			if (Filters != MessageFilter.None)
			{
				AddParameter( "filters", ( ( int ) Filters ).ToString() );
			}
			if (Offset!=0)
			{
				AddParameter( "offset", Offset.ToString() );
			}
			if (PreviewLength!=90)
			{
				AddParameter( "preview_length", PreviewLength.ToString() );
			}
			base.Compile();
		}

		protected override void ParseData(string data)
		{
			ListingResponce responce = Serializer.LoadObjectXmlString<ListingResponce>(data);
			base.ParseData(data);
		}

		public bool Out
		{
			get; set;
		}

		public int Count
		{
			get
			{
				return _count;
			}
			set
			{

				if ( ( value > 100 ) || ( value < 0 ) )
				{
					throw new ArgumentException( "Должно быть в пределах от 1 до 100.0- автоматический режим", "value" );
				}

				_count = value;
			}
		}

		public MessageFilter Filters
		{
			get; set;
		}

		public int Offset
		{
			get; set;
		}

		public int PreviewLength
		{
			get; set;
		}
	}

	public enum MessageFilter
	{
		None = 0,
		OnlyUnread = 1,
		NotFromChat = 2,
		OnlyFriends = 4
	}
}
